package yxy.cherry.paycenter.channelmodule.jhh5;

import java.util.ArrayList;

import org.joda.time.DateTime;

import com.alibaba.fastjson.JSONObject;

import yxy.apple.logger.Logger;
import yxy.cherry.data.bean.charge;
import yxy.cherry.paycenter.channelmodule.PayMoudle_channel;
import yxy.cherry.paycenter.database.db.orders;
import yxy.game.pm2.bean.Currency;
import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.bean.channel.SdkChannel;
import yxy.game.pm2.bean.module.OrderInfoModule;
import yxy.game.pm2.bean.order.OrderInfo;

public class PayMoudle_jhh5 extends PayMoudle_channel {

	static final Logger logger = Logger.create(PayMoudle_jhh5.class);
	
	@Override
	public JSONObject dealPay(JSONObject infoobj) {
		return null;
	}

	@Override
	public JSONObject createOrderInfo(JSONObject infoobj, orders o) {
		JSONObject parseobj = new JSONObject();
		
//		uid: 30527238, //江湖系统uid
//	    orderNo  'TEST10000', //外部订单号（调用方产生的订单号）
//	    amount  100,            //金额（分）
//		ratio "100",  //游戏币比例，例如1元人民币=100元宝，则比例为100
//	    productNo: 'TEST10000', //商品id
//	    productName: '测试商品', //商品名称
//	    productDesc:'',         //商品简介
//	    serverId:'',            //区服Id
//	    serverName:'',          //区服名称
//	    roleId:'',              //角色Id
//	    roleName:'',            //角色名称
//	    reservedParams: '', //透传参数，在支付通知里原样返回
//		currencyName  "钻石", //游戏中使用的货币名称，元宝、钻石等等		
		
		PlayerBean pb = PlayerBean.get(o.getPlayercode());
		
//		String uid = String.valueOf(pb.getUid());
		String orderNo = o.getMyorderid();
		int amount = o.getGoodsprice();	//单位 分
		int ratio = 10;
		int productNo = o.getGoodsid();		//TODO:
		String productName = o.getGoodsname();
		String productDesc = o.getGoodsname();
		int serverId = o.getServerid();
		String serverName = serverId + "服";
		String roleId = o.getPlayercode();
		String roleName = pb.getName();
		String currencyName = "元宝";
		
//		parseobj.put("uid", uid);
		parseobj.put("orderNo", orderNo);
		parseobj.put("amount", amount);
		parseobj.put("ratio", ratio);
		parseobj.put("productNo", productNo);
		parseobj.put("productName", productName);
		parseobj.put("productDesc", productDesc);
		parseobj.put("serverId", serverId);
		parseobj.put("serverName", serverName);
		parseobj.put("roleId", roleId);
		parseobj.put("roleName", roleName);
		parseobj.put("currencyName", currencyName);
		parseobj.put("reservedParams", "");
		return parseobj;
	}
	
	public orders createOrderJHH5(int dataid, String playercode, int serverid, int acttype) {
		orders o = createOrder(getChannel(), dataid, acttype, playercode, serverid);
		addOrder(o);
		return o;
	}
	
	/**
	 * 创建 OrderInfo
	 * @param o
	 * @param curs
	 * @param c
	 * @param payamount
	 */
	public void createOrderInfoModule(orders o, ArrayList<Currency> curs, charge c, int payamount) {
		createOrderInfoModule(o, curs, c.getVipexp(), payamount);
	}
	
	/**
	 * 
	 * @param o
	 * @param curs
	 * @param vipexp
	 * @return
	 */
	public void createOrderInfoModule(orders o, ArrayList<Currency> curs, int vipexp, int payamount) {
		OrderInfo oi = OrderInfoModule.createOrderInfo(o.getGoodsid(), o.getChannel(), o.getMyorderid(), new DateTime(o.getCreatetime().getTime()), 
				OrderInfoModule.orderinforuning, o.getPlatorderid(), o.getActtype(), o.getPlayercode(), curs, 
				o.getServerid(), DateTime.now(), vipexp, payamount, o.getGoodsprice());
		OrderInfo.set(o.getPlayercode(), oi);
	}

	@Override
	public String getChannel() {
		return SdkChannel.sdk_jhh5;
	}

}
